#ifndef APPLICATION_H
#define APPLICATION_H

#include <stdbool.h>

typedef enum
{
	error = 0,
	power_on = 1,
	power_off,

}k15_signal_t;

typedef enum
{
	auto_mode   = 0,
	manual_mode = 1
} blow_mode_t;

typedef enum
{
	driver_not_blow = 0,
	driver_need_blow
} driver_signal_t;

typedef enum
{
	none = 0,
	blow_delay,
	first_blow,
	first_interval,
    second_blow,
	second_interval,
    third_blow,
    end
} blow_back_process_t;

typedef struct 
{
	bool pick_up_flag;		           // 任务挂起标志位
	bool auto_blow_command;			   // 自动反吹指令
	bool manual_blow_command;          // 手动反吹指令
	unsigned short blow_delay_time;    // 反吹延迟时间
	unsigned short blow_interval_time; // 反吹间隔时间
	
	unsigned short blow_delay_count;      // 延迟时间计数值
	unsigned short blow_interval_count;   // 间隔时间计数值
	
	blow_back_process_t process;
} blow_back_t;

typedef struct
{
	float ubus;			           // 母线电压（V）
	float heater_cur;	           // 加热器电流（A）
	float valve_cur;	           // 电磁阀电流（A）
	float temperature;	           // 环境温度（℃）
	k15_signal_t k15_signal;       // 钥匙电信号
	blow_mode_t blow_mode;	       // 反吹模式 0 --> 自动, 1--> 手动
	driver_signal_t driver_signal; // 驾驶员发出的反吹信号
} controller_t;

extern controller_t controller;
extern blow_back_t blow_back;

extern unsigned short power_up_count;
extern unsigned short power_down_count;

extern unsigned short mode_button_release_count;
extern unsigned short mode_button_press_count;

extern unsigned short driver_button_press_count;
extern unsigned short driver_button_release_count;

extern unsigned char task_1ms_flg;

extern void update_data(void);
extern void blow_back_logic(void);
extern void blow_back_init(void);
extern void controller_init(void);

void auto_blow_back_process(void);
void manual_blow_back_process(void);

#endif 

